package com.poetize.plus.entity.dto;

import com.poetize.plus.entity.po.Article;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Null;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Update;

/**
 * @Author zuosy
 * @Date 2024/3/30 15:43
 **/
public record ArticleDTO(
        @Schema(description = "id")
        @Null(message = "id必须为空", groups = {Insert.class})
        @NotNull(message = "id不能为空", groups = {Update.class})
        Long id,

        @Schema(description = "分类")
        @NotNull(message = "分类不能为空", groups = {Insert.class, Update.class})
        Long sortId,

        @Schema(description = "标签")
        @NotNull(message = "标签不能为空", groups = {Insert.class, Update.class})
        Long labelId,

        @Schema(description = "封面")
        @NotBlank(message = "封面不能为空", groups = {Insert.class, Update.class})
        String articleCover,

        @Schema(description = "标题")
        @NotBlank(message = "标题不能为空", groups = {Insert.class, Update.class})
        String articleTitle,

        @Schema(description = "内容")
        @NotBlank(message = "内容不能为空", groups = {Insert.class, Update.class})
        String articleContent,

        @Schema(description = "是否可见")
        @NotNull(message = "是否可见不能为空", groups = {Insert.class, Update.class})
        Boolean viewStatus,

        @Schema(description = "是否推荐")
        @NotNull(message = "是否推荐不能为空", groups = {Insert.class, Update.class})
        Boolean recommendStatus,

        @Schema(description = "是否启用评论")
        @NotNull(message = "是否启用评论不能为空", groups = {Insert.class, Update.class})
        Boolean commentStatus,

        @Schema(description = "是否加密")
        @NotNull(message = "是否加密不能为空", groups = {Insert.class, Update.class})
        Boolean encoderStatus,

        @Schema(description = "密码")
        String password
) {

        /**
         * DTO转实体类
         * @param articleDTO
         * @return
         */
        public static Article convertDTO(ArticleDTO articleDTO){
                return new Article(
                        articleDTO.id,
                        articleDTO.sortId,
                        articleDTO.labelId,
                        articleDTO.articleCover,
                        articleDTO.articleTitle,
                        articleDTO.articleContent,
                        articleDTO.password,
                        articleDTO.viewStatus,
                        articleDTO.encoderStatus,
                        0,
                        articleDTO.commentStatus,
                        articleDTO.recommendStatus);
        }
}
